package com.xrj4j.k_tally.utils

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.Date

object DateUtil {

    private val format1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")

    private val format2 = DateTimeFormatter.ofPattern("yyyy-MM-dd")

    fun now(): Date {
        return Date()
    }

    fun timestamp(): Long {
        return Date().time
    }

    fun formatDate(date: LocalDateTime): String {
        return format1.format(date)
    }

    fun formatDate2(date: LocalDateTime): String {
        return format2.format(date)
    }

    fun parseDate(date: String): LocalDateTime {
        return LocalDateTime.parse(date, format1)
    }

    /**
     * 获取真实的年份
     */
    fun year(date: LocalDateTime): Int {
        return date.year
    }

    /**
     * 获取真实的月份
     */
    fun month(date: LocalDateTime): Int {
        return date.month.value
    }

    /**
     * 获取月份天数
     */
    fun day(date: LocalDateTime): Int {
        return date.dayOfMonth
    }

}